package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author rookie001
 * @creat 2023-05-02-10:11
 */
@Mapper
public interface OrderMapper {
    //订单表中插入数据
    void insert(Orders order);
    //根据订单号和用户id查询订单

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    // 修改订单信息
    void update(Orders orders);

    //分页查询
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    //查询订单表数据
    @Select("select * from orders where id= #{Id}")
    Orders getById(Long id);

    //查询各个订单数量
    @Select("select count(*) from orders where status=#{status}")
    Integer countNum(Integer status);

    //根据状态和下单时间查询订单
    @Select("select *from orders where status=#{status} and order_time <#{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);

    //动态条件统计营业额
    Double sumByMap(Map map);

    //查询
    @Select("SELECT DATE(order_time) orderTime ,SUM(amount) amount FROM  orders  WHERE order_time BETWEEN #{begin} AND #{end} AND STATUS = #{status}" +
            " GROUP BY DATE(order_time)  ;")
    List<Map<String, Object>> getTurnover(LocalDateTime beginTime, LocalDateTime endTime, Integer completed);

    //根据动态条件统计订单数量
    Integer countByMap(Map map);

    //查询指定时间区间内的销量排名top10
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
